//
//  VKStudyDaCardView.m
//  V-Learn
//
//  Created by liubo on 2019/3/1.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKStudyDaCardView.h"

@implementation VKStudyDaCardView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setuplayout];
    }
    return self;
}

-(void)setuplayout{
    UIButton *downbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    downbtn.backgroundColor = [UIColor colorWithRed:127/255.0 green:127/255.0 blue:127/255.0 alpha:0.4];
    
    [self addSubview:downbtn];
    [downbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [downbtn addTarget:self action:@selector(downbtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *downView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen cz_screenHeight], [UIScreen cz_screenWidth], 158)];
    [downbtn addSubview:downView];
    self.downView = downView;
    downView.backgroundColor = [UIColor whiteColor];
    
    [UIView animateWithDuration:0.15 animations:^{
        downView.frame = CGRectMake(0, [UIScreen cz_screenHeight] - 158, [UIScreen cz_screenWidth], 158);
    }];
    // 添加
    
    NSArray *titleArray = @[@"相片或视频",@"备课",@"取消"];
    
    for (int i = 0; i < 3; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [downView addSubview:button];
        [button setTitle:titleArray[i] forState:UIControlStateNormal];
//        button.backgroundColor = [UIColor cz_randomColor];
        [button setTitleColor:[UIColor cz_colorWithRed:51 green:51 blue:51] forState:UIControlStateNormal];
        button.tag = i;
        [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 0 ) {
            UIView *lineView = [[UIView alloc]init];
            [downView addSubview:lineView];
            lineView.backgroundColor = [UIColor cz_colorWithRed:229 green:229 blue:229];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@1);
                make.left.right.equalTo(@0);
                make.top.mas_equalTo(button.mas_bottom);
            }];
            
            button.frame = CGRectMake(0, i * 50, [UIScreen cz_screenWidth], 50);
        }else if (i == 2){
            button.frame = CGRectMake(0, i * 50 + 8, [UIScreen cz_screenWidth], 50);
        }else{
            button.frame = CGRectMake(0, i * 50 + 1, [UIScreen cz_screenWidth], 50);
            UIView *lineView = [[UIView alloc]init];
            [downView addSubview:lineView];
            lineView.backgroundColor = [UIColor cz_colorWithRed:242 green:242 blue:242];
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.height.equalTo(@6);
                make.left.right.equalTo(@0);
                make.top.mas_equalTo(button.mas_bottom);
            }];
        }
        
    }
}
- (void)buttonClick:(UIButton *)sender{
        
    if(sender.tag == 0){ // 相片或视频
        if (_daCardBlock) {
            self.daCardBlock(sender.tag);
        }
    }else if (sender.tag == 1){// 备课
        if (_daCardBlock) {
            self.daCardBlock(sender.tag);
        }
    }else if (sender.tag == 2){// 取消
        [self cancelDownView];
    }
}
// 取消
- (void)cancelDownView{
    [UIView animateWithDuration:0.15 animations:^{
        self.downView.frame = CGRectMake(0, [UIScreen cz_screenHeight], [UIScreen cz_screenWidth], 158);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (void)downbtnClick{
    if (_daCardViewBlock) {
        self.daCardViewBlock();
    }
}
@end
